package onlineclass.service;


import onlineclass.dao.OUserMapper;
import onlineclass.entity.OUser;
import onlineclass.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class OUserService {
    private static Logger Log = LoggerFactory.getLogger(OUserService.class);
    public static final OUserService INST = new OUserService();
    public int add(OUser ouser){
        SqlSession s = MyBatisUtil.get();
        try {
            OUserMapper mapper = s.getMapper(OUserMapper.class);
            return mapper.add(ouser);
        }  finally {
            MyBatisUtil.close(s);
        }
    }
    public int update(OUser ouser){
        SqlSession s = MyBatisUtil.get();
        try {
            OUserMapper mapper = s.getMapper(OUserMapper.class);
            return mapper.update(ouser);
        }  finally {
            MyBatisUtil.close(s);
        }
    }
    public int del(long id){
        SqlSession s = MyBatisUtil.get();
        try {
            OUserMapper mapper = s.getMapper(OUserMapper.class);
            return mapper.del(id);
        }  finally {
            MyBatisUtil.close(s);
        }
    }
    public OUser get(long id){
        SqlSession s = MyBatisUtil.get();
        try {
            OUserMapper mapper = s.getMapper(OUserMapper.class);
            return mapper.get(id);
        }  finally {
            MyBatisUtil.close(s);
        }
    }

    public int findTotal( String name,String tele){
        SqlSession s = MyBatisUtil.get();
        try {
            OUserMapper mapper = s.getMapper(OUserMapper.class);
            return mapper.findTotal(name,tele);
        }  finally {
            MyBatisUtil.close(s);
        }
    }
    public List<OUser> find(int pageNo,  int pageSize,  String name, String tele){
        SqlSession s = MyBatisUtil.get();
        try {
            OUserMapper mapper = s.getMapper(OUserMapper.class);
            return mapper.find(pageNo,pageSize,name,tele);
        }  finally {
            MyBatisUtil.close(s);
        }
    }
}
